package com.shujia.spark.core

import org.apache.spark.{SparkConf, SparkContext}

object Demo4Filter {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("Demo4Filter")

    val sc = new SparkContext(conf)

    val studentsRDD = sc.textFile("spark/data/students.txt")

    //取出性别为男的学生

    /**
      * filter  过滤数据
      * 函数返回true保留这一样数据  返回false过滤这一行数据
      *
      */

    val filterRDD = studentsRDD.filter(line => {
      val gender = line.split(",")(3)

      gender.equals("男")
    })

    //触发job任务
    filterRDD.foreach(println)

    println("=" * 100)

    //取出女学生
    val filterRDD1 = studentsRDD.filter(line => {
      val gender = line.split(",")(3)

      gender.equals("女")
    })

    //触发job
    filterRDD1.foreach(println)


  }

}
